<?php
require('../../public/connection.php');
$data1 = json_decode(file_get_contents('php://input'), true);
for ($j=0,$conut1=count($data1); $j < $conut1; $j++) { 
    $data = $data1[$j];
    for ($i=0,$conut2=count($data); $i < $conut2; $i++) { 
        $time = getDateTime();
        $sql = "insert into accountings values(null,'{$data[$i]["name"]}',{$data[$i]["money"]},{$data[$i]["mode"]},'{$data[$i]["remarks"]}','{$data[$i]["date"]}','{$time}');";
        $query = mysqli_query($connect, $sql);
        if (!$query) {
            echo (json_encode(array("code" => 300, "msg" => "添加失败")));
        };
        echo (json_encode(array("code" => 0, "msg" => "添加成功")));
    }
}

/*格式类型
[
    [
        {
            "date": "2021-01-01",
            "name": "网购",
            "money": 0.87,
            "remarks": "网购",
            "mode": 2
        },
        {
            "date": "2021-01-01",
            "name": "网购",
            "money": 0.9,
            "remarks": "网购",
            "mode": 2
        },
        {
            "date": "2021-01-03",
            "name": "网购",
            "money": 0.24,
            "remarks": "网购",
            "mode": 2
        }
    ],
    [
        {
            "date": "2021-01-01",
            "name": "网购",
            "money": 0.87,
            "remarks": "网购",
            "mode": 2
        },
        {
            "date": "2021-01-01",
            "name": "网购",
            "money": 0.9,
            "remarks": "网购",
            "mode": 2
        },
        {
            "date": "2021-01-03",
            "name": "网购",
            "money": 0.24,
            "remarks": "网购",
            "mode": 2
        }
    ]
]*/